package dao

import (
	"fmt"
	"github.com/jinzhu/gorm"
)

type FilterProductModel struct {
	Id            int64  `gorm:"primaryKey"`
	Nickname      string `gorm:"column:nickname;type:varchar(255)"`
	ModelName     string `gorm:"column:modelName;type:varchar(255)"`
	DispModelName string `gorm:"column:dispModelName;type:varchar(255)"`
	ProductId     string `gorm:"column:productId;type:varchar(255)"`
}

type FilterProductModelDao struct {
	db *gorm.DB
}

func NewFilterProductModelDao(db *gorm.DB) *FilterProductModelDao {
	return &FilterProductModelDao{db: db}
}

func (f *FilterProductModelDao) CreateFilterProductModel(param *FilterProductModel) int64 {
	err := f.db.Create(param).Error
	if err != nil {
		fmt.Print("写入 FilterProductModel db错误", err)
	}
	return param.Id
}

func (f *FilterProductModelDao) GetListByProductId(productId string) []*FilterProductModel {
	res := make([]*FilterProductModel, 0)
	f.db.Where("productId = ?", productId).Find(&res)
	return res
}
